<script setup lang="ts">
import router from '@/router';
import { useMenuStore } from '@/stores/menu';
import { useUserStore } from '@/stores/user';
import { ElMessage, ElMessageBox } from 'element-plus';

// 获取存储库
const store = useUserStore()
// 退出登录业务
const onLayout = () =>{
  ElMessageBox.confirm('确定要退出登录吗？',{
    title:'确认退出',
    confirmButtonText:'确定',
    cancelButtonText:'取消'
  }).then(()=>{
    
    ElMessage({
      type:'success',
      message:'退出成功'
    })
      // 删除用户token
      store.removeToken()
      // 清除路由
      const menuStore = useMenuStore()
      // 清理用户信息
      store.clearProfile()
      // 跳转到登录页
      router.replace('/login')
  }).catch(()=>{
    ElMessage({
      type:"info",
      message:'取消退出'
    })
  })
  
  
}

</script>

<template>
  <div class="nav-bar">
    <!-- breadcrumb -->
    <div></div>
    <!-- dropdown -->
    <el-dropdown>
      <div class="user-wrapper">{{ store.profile.name }}</div>
      <template #dropdown>
        <el-dropdown-menu >
          <el-dropdown-item>首页</el-dropdown-item>
          <el-dropdown-item>项目地址</el-dropdown-item>
          <el-dropdown-item @click="onLayout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<style lang="scss" scoped>
.nav-bar {
  height: 60px;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;

  .user-wrapper {
    outline: none;
    cursor: default;
    color: var(--el-color-black);
  }
}
</style>
